import { InjectionKey } from "vue";
import { createStore, useStore as baseUseStore, Store } from "vuex";

export interface State {
  count: number;
}

export const key: InjectionKey<Store<State>> = Symbol();

export const store = createStore<State>({
  state: {
    count: 1,
  },
  getters: {
    getCount: ({ count }) => count,
  },
  mutations: {
    SET_COUNT(state, value: number = 1) {
      state.count += value;
    },
  },
  actions: {
    async handleSetCount({ commit }) {
      commit("SET_COUNT");
    },
  },
  modules: {},
});

export function useStore() {
  return baseUseStore(key);
}
